package com.baohua.controller;

import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.baohua.exception.BaohuaSystemException;
import com.baohua.model.Member;
import com.baohua.service.AutoCompleteService;

@Controller
@RequestMapping("/autoComplete")
public class AutoCompleteControll {

	private AutoCompleteService autoCompleteService;

	public AutoCompleteService getAutoCompleteService() {
		return autoCompleteService;
	}

	@Resource(name = "autoCompleteService")
	public void setAutoCompleteService(AutoCompleteService autoCompleteService) {
		this.autoCompleteService = autoCompleteService;
	}

	/**
	 * AutoComplete跳转
	 * 
	 * */
	@RequestMapping(value="/autoComplete1" ,method = RequestMethod.GET)
	public ModelAndView AutoComplete () {
		Member  member = new Member();
		return new ModelAndView("autoComplete","member",member);
	}
	
	/**
	 * AutoComplete自动完成 测试
	 * 
	 * @throws BaohuaSystemException
	 * 
	 * */
	@RequestMapping(value = "/list", 
			method = RequestMethod.GET, 
			headers="Accept=*/*")
	public  @ResponseBody List<String> memberOrder(@RequestParam("term") String query) {
		List<String> list = autoCompleteService.getAllMemberNo(query);
		return list;
	}

	/**
	 * AutoComplete 填充测试
	 * 
	 * @throws BaohuaSystemException
	 * 
	 * */
	@RequestMapping("/memberName")
	public String getMemberName (String memberNo) {
		String memberName = autoCompleteService.getMemberName(memberNo);
		return memberName;
	}
}
